package com.ruoyi.wms.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.wms.domain.WmsOutCheckItem;
import com.ruoyi.wms.mapper.WmsOutCheckItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.mapper.WmsOutCheckHeadMapper;
import com.ruoyi.wms.domain.WmsOutCheckHead;
import com.ruoyi.wms.service.IWmsOutCheckHeadService;
import com.ruoyi.common.core.text.Convert;

/**
 * 出库Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-15
 */
@Service
public class WmsOutCheckHeadServiceImpl implements IWmsOutCheckHeadService 
{
    @Autowired
    private WmsOutCheckHeadMapper wmsOutCheckHeadMapper;

    @Autowired
    private WmsOutCheckItemMapper wmsOutCheckItemMapper;

    /**
     * 查询出库
     * 
     * @param id 出库主键
     * @return 出库
     */
    @Override
    public WmsOutCheckHead selectWmsOutCheckHeadById(Long id)
    {
        return wmsOutCheckHeadMapper.selectWmsOutCheckHeadById(id);
    }

    /**
     * 查询出库列表
     * 
     * @param wmsOutCheckHead 出库
     * @return 出库
     */
    @Override
    public List<WmsOutCheckHead> selectWmsOutCheckHeadList(WmsOutCheckHead wmsOutCheckHead)
    {
        return wmsOutCheckHeadMapper.selectWmsOutCheckHeadList(wmsOutCheckHead);
    }

    /**
     * 新增出库
     * 
     * @param wmsOutCheckHead 出库
     * @return 结果
     */
    @Override
    public int insertWmsOutCheckHead(WmsOutCheckHead wmsOutCheckHead)
    {
        wmsOutCheckHead.setCreateTime(DateUtils.getNowDate());
        wmsOutCheckHead.setDeptId(ShiroUtils.getSysUser().getDeptId());
        wmsOutCheckHead.setDeptName(ShiroUtils.getSysUser().getDept().getDeptName());
        wmsOutCheckHeadMapper.insertWmsOutCheckHead(wmsOutCheckHead);
        for(WmsOutCheckItem item:wmsOutCheckHead.getItemList()){
            item.setCreateBy(ShiroUtils.getSysUser().getUserName());
            item.setCreateTime(new Date());
            item.setOutTime(new Date());
            item.setHeadId(wmsOutCheckHead.getId());
            wmsOutCheckItemMapper.insertWmsOutCheckItem(item);
        }
        return 1;
    }

    /**
     * 修改出库
     * 
     * @param wmsOutCheckHead 出库
     * @return 结果
     */
    @Override
    public int updateWmsOutCheckHead(WmsOutCheckHead wmsOutCheckHead)
    {
        wmsOutCheckHead.setUpdateTime(DateUtils.getNowDate());
        return wmsOutCheckHeadMapper.updateWmsOutCheckHead(wmsOutCheckHead);
    }

    /**
     * 批量删除出库
     * 
     * @param ids 需要删除的出库主键
     * @return 结果
     */
    @Override
    public int deleteWmsOutCheckHeadByIds(String ids)
    {
        return wmsOutCheckHeadMapper.deleteWmsOutCheckHeadByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除出库信息
     * 
     * @param id 出库主键
     * @return 结果
     */
    @Override
    public int deleteWmsOutCheckHeadById(Long id)
    {
        return wmsOutCheckHeadMapper.deleteWmsOutCheckHeadById(id);
    }
}
